package vell.velllock.service;

import vell.velllock.activity.VellLock;
import vell.velllock.util.VellLockUtil;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class MyLockScreenService extends Service
{
	private final String ACT_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
	private final String ACT_SCREEN_ON = "android.intent.action.SCREEN_ON";

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	@Override
	public void onCreate() {
		super.onCreate();

		IntentFilter intentFilterOff = new IntentFilter(ACT_SCREEN_OFF);
		registerReceiver(mScreenOff, intentFilterOff);
		IntentFilter intentFilterOn = new IntentFilter(ACT_SCREEN_ON);
		registerReceiver(mScreenOn, intentFilterOn);
		Toast.makeText(this, "VellLock ScreenService starting", Toast.LENGTH_SHORT).show();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
		unregisterReceiver(mScreenOff);
	}

	private BroadcastReceiver mScreenOn = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, Intent intent) {
		}
	};

	private BroadcastReceiver mScreenOff = new BroadcastReceiver() {

		@Override
		public void onReceive(Context context, Intent intent) {
			try {
				VellLockUtil.startActivity(context, VellLock.class);
			} catch (Exception e) {
				Log.e("", "***********onReceive Error=" + e);
			}
		}
	};
}
